<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"></meta>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <link rel="stylesheet" href="http://1.xinli2017.applinzi.com/login/css/mui.min.css"/>
    <script src="http://1.xinli2017.applinzi.com/weixin/js/jquery.min.js"></script>
    <script src="http://1.xinli2017.applinzi.com/weixin/js/mui.min.js"></script>
    <script type="text/javascript">
        document.addEventListener('plusready', function () {
            //console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"
        });
    </script>
    <style>
        body {
            font-size: 16px;
        }
        input {
            height: 35px;
        }
         input[type=text] {
            border: 0;
            width: 62%;
            height: 40px;
        }
        input[placeholder] {
            font-size: 14px;
        }

        input[type=button] {
           border: 0;
            width: 34%;
            margin-left: 5px;
            height: 40px;
        }
        #phone{
            width: 100%;
            margin:10px 0;
        }
        .bor{
          background: #fff;
          margin-top: 10px;

        }
        .bor label{
          width: 30%;
        }
         .mui-input-row label~input, .mui-input-row label~select, .mui-input-row label~textarea{
          width: 70%;
         }
    </style>
</head>
<body style="padding: 0 15px">
<script>
		try{
			window.android.invokeMethod(0,["确认绑卡信息","true"])
				}catch(e){
			console.log(e)
		}
	</script>
<header class="mui-bar mui-bar-nav" style="background:#37c3e7">
    <h1 class="mui-title" style="color:#fff;">绑卡验证</h1>
</header>
<div class="mui-content" style="margin-top: 10px;">
    <input type="text" id="phone" placeholder="请输入手机号" readonly="readonly"/>
    <div class="mui-input-row bor" id="avaliable2" style="display:block">
        <label>信用额度</label>
        <input type="text" id="avaliable" placeholder="请输入信用额度">
    </div>
    <div class="mui-input-row bor" id="reciept2" style="display:block">
        <label>账单日</label>
        <input type="text" id="reciept" placeholder="请输入账单日">
    </div>
    <div class="mui-input-row bor" id="paymentday2" style="margin-bottom: 10px;display:block;">
        <label>还款日</label>
        <input type="text" id="paymentday" placeholder="请输入还款日">
    </div>
    <input type="text" id="p14" placeholder="请输入短信验证码" />
    <input type="button" id="btn0" class=" mui-right" value="获取验证码" />
</div>
<div class="mui-input-row" style="width:100%;margin:0px auto;">
    <button id="btn" class="mui-btn mui-btn-primary"
            style="width:100%;height:40px;padding:10px 0;background:#37c3e7;border:0;">确定
    </button>
</div>
 <div id="show" class="mui-input-row"
     style="width:50%;position:fixed;top:50%;left:50%;transform: translate(-50%,-50%);z-index: 100;text-align: center;background:rgba(0,0,0,.7);color:#fff; padding: 12px 0;border-radius: 10px;display: none; font-weight: 400;font-size: 14px;"></div>
        </div>
<span style="display:none" id="p1" th:text="${P1_bizType}"></span>
<span style="display:none" id="p2" th:text="${P2_customerNumber}"></span>
<span style="display:none" id="p3" th:text="${P3_userId}"></span>
<span style="display:none" id="p4" th:text="${P4_orderId}"></span>
<span style="display:none" id="p5" th:text="${P5_timestamp}"></span>
<span style="display:none" id="p6" th:text="${P6_payerName}"></span>
<span style="display:none" id="p7" th:text="${P7_idCardType}"></span>
<span style="display:none" id="p8" th:text="${P8_idCardNo}"></span>
<span style="display:none" id="p9" th:text="${P9_cardNo}"></span>
<span style="display:none" id="p10" th:text="${P10_year}"></span>
<span style="display:none" id="p11" th:text="${P11_month}"></span>
<span style="display:none" id="p12" th:text="${P12_cvv2}"></span>
<span style="display:none" id="p13" th:text="${P13_phone}"></span>
<span style="display:none" id="bn" th:text="${bankName}"></span>
<span style="display:none" id="oip" th:text="${orderIp}"></span>
<span style="display:none" id="loginPhone" th:text="${loginPhone}"></span>
<span style="display:none" id="bindd"></span>
<script  type="text/javascript">
	$('#btn').attr("disabled","disabled");
	var P1_bizType = $("#p1").text();
	var P2_customerNumber = $("#p2").text();
	var P3_userId = $("#p3").text();
	var P4_orderId = $("#p4").text();
	var P5_timestamp = $("#p5").text();
	var P6_payerName = $("#p6").text();
	var P7_idCardType = $("#p7").text();
	var P8_idCardNo = $("#p8").text();
	var P9_cardNo = $("#p9").text();
	var P10_year = $("#p10").text();
	var P11_month = $("#p11").text();
	var P12_cvv2 = $("#p12").text();
	if(P12_cvv2==""){
           	   	  			document.getElementById("avaliable2").style.display="none";
           	   	  			document.getElementById("reciept2").style.display="none";
           	   	  			document.getElementById("paymentday2").style.display="none";
           	   	  		}
	var P13_phone = $("#p13").text();
	var bankName = $("#bn").text();
	var orderIp = $("#oip").text();
	var loginPhone = $("#loginPhone").text();
	$("#phone").val(P13_phone);
	function turntopage(url){
			mui.openWindow({
			
			url:url,
			
			});
			
		}

    $(function () {
         var wait = 60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value = "获取验证码";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value = "重新发送(" + wait + ")";
                wait--;
                setTimeout(function () {
                            time(o)
                        },
                        1000)
            }
        }
        $("#btn0").click(function () {//获取验证码
            var phone = $('#phone').val();
            if (phone == '') {
                $('#show').html('手机号码不能为空').stop().fadeIn(100)
                $('#show').fadeOut(2000)        
            } else {
                 time(this);
			var jsonObj = {
				"P1_bizType":"QuickPayBindCardValidateCode",
				"P2_customerNumber":P2_customerNumber,
				"P3_userId":P3_userId,
				"P4_orderId":P4_orderId,
				"P5_timestamp":P5_timestamp,
				"P6_cardNo":P9_cardNo,
				"P7_phone":P13_phone
			}
			$.ajax({
				url: 'http://47.104.158.3/v1.0/paymentchannel/topup/sendValidateCode',
	            type: 'POST',
	            data: jsonObj,
	            dataType: 'JSON',
	            success: function (data) {
	            	if("00"==data.code){
	            		$('#btn').removeAttr("disabled");
	            	}else{
	            		alert("短信发送失败！");
	            	}
	            },
	            error: function () {
	                console.log('加载数据异常，请重试!');
	                alert("短信发送失败！");
	            }
			});
            }
        });
        $('#btn').click(function () {
			if(""==$("#p14").val()||null==$("#p14").val()){
				alert("请输入验证码！");
				return;
			}
			if(P12_cvv2!=""){
				var ym = $("#reciept").val();
				var ym2 = $("#paymentday").val();
				var ym3 = $("#avaliable").val();
				if (isNaN(ym)||isNaN(ym2)||isNaN(ym3)) {
			　　　　alert("请输入数字");
			　　　　return ;
			　　}else{
					if(ym>28||ym2>28){
						alert("账单日和还款日不能大于28");
				　　　　return ;
					}
					if(ym<1||ym2<1){
						alert("账单日和还款日不能小于1");
				　　　　return ;
					}
				} 
			}
			$("#btn").text("绑卡中");
			$('#btn').attr("disabled","disabled");
			var jsonObj = {
				"P1_bizType":P1_bizType,
				"P2_customerNumber":P2_customerNumber,
				"P3_userId":P3_userId,
				"P4_orderId":P4_orderId,
				"P5_timestamp":P5_timestamp,
				"P6_payerName":P6_payerName,
				"P7_idCardType":P7_idCardType,
				"P8_idCardNo":P8_idCardNo,
				"P9_cardNo":P9_cardNo,
				"P10_year":P10_year,
				"P11_month":P11_month,
				"P12_cvv2":P12_cvv2,
				"P13_phone":P13_phone,
				"P14_validateCode":$("#p14").val()
			}
			$.ajax({
            url: 'http://47.104.158.3/v1.0/paymentchannel/topup/bindCard',
            type: 'POST',
            async: false,
            data: jsonObj,
            dataType: 'JSON',
            success: function (data) {
            	console.log(data);
               if(null!=data&&undefined!=data){
               	  var obj = data.json;
               	  if(undefined==obj){
               	  	alert(data.message);
               	  	return;
               	  }
               	  console.log(obj);
               	  data = obj;
           	   	  if("0000"==data.rt2_retCode){
           	   	  	if("SUCCESS"==data.rt7_bindStatus){
           	   	  		var rt10_bindId = data.rt10_bindId;
           	   	  		$("#bindd").text(rt10_bindId);
           	   	  		var cardType = "0";
           	   	  		if(P12_cvv2==""){
           	   	  			cardType = "1";
           	   	  		}
           	   	  		var jsonObj2 = {
							"userId":P3_userId,
							"exemption":"0",
							"phone":P13_phone,
							"bankName":bankName,
							"name":P6_payerName,
							"cardNo":P8_idCardNo,
							"bindId":rt10_bindId,
							"bankCard":P9_cardNo,
							"cardType":cardType,
							"status":"0",
							"avaliable":$("#avaliable").val(),
							"recieptDay":$("#reciept").val(),
							"paymentDay":$("#paymentday").val(),
							"balance":"0",
							"frozenBalance":"0",
							"bankCardYear":P10_year,
							"bankCardMonth":P11_month,
							"loginPhone":loginPhone,
							"cvv":P12_cvv2
						}
                        $.ajax({
                        url: 'http://47.104.158.3/v1.0/paymentchannel/hlregister/add',
			            type: 'POST',
			            async: false,
			            data: jsonObj2,
			            dataType: 'JSON',
			            success: function (data) {
			            	if("000000"==data.resp_code){
			            		turntopage("http://47.104.158.3/v1.0/paymentchannel/topup/helipay?P2_customerNumber="+P2_customerNumber+"&P3_bindId="+rt10_bindId+"&P4_userId="+P3_userId+"&P5_orderId="+P4_orderId+"&reqTime="+P5_timestamp+"&P8_orderAmount=2&P9_phone="+P13_phone+"&P9_goodsName=首次交易认证&P13_orderIp="+orderIp);
		  						
			            	}else{
			            		turntopage("http://1.xinli2017.applinzi.com/login/bangkaerror.html");
			            	}
			            },
			            error: function () {
			                console.log('加载数据异常，请重试!');
			                alert("绑卡信息保存失败！");
			            }
                        });
                        
                        
           	   	    }else{
               			alert("绑卡失败！");
               	    }
           	   	  }else{
               		alert("绑卡失败！");
               	  }
               }else{
               	alert("绑卡失败！");
               }
            },
            error: function () {
                console.log('加载数据异常，请重试!');
                alert("绑卡失败！");
            }
        });
        })  
    });
</script>
</body>
</html>